package com.community.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.community.dao.IBaseDao;
import com.community.entity.CourseEnroll;
import com.community.service.ICourseEnrollService;

@Service
public class CourseEnrollServiceImpl implements ICourseEnrollService{

	@Autowired
	private IBaseDao<CourseEnroll> cedao;
	
	@Override
	public CourseEnroll getCourseEnrollByUserIdAndCourseId(Long userid, Long courseid) {
		// TODO Auto-generated method stub
		String jpql = "from CourseEnroll where userId = ?1 and courseId =?2";
		Map<String, Object> params = new HashMap<>();
		params.put("1", userid);
		params.put("2", courseid);
		return cedao.get(jpql, params);
	}

	@Override
	public void addCourseEnroll(CourseEnroll c) {
		// TODO Auto-generated method stub
		cedao.save(c);
	}

	@Override
	public List<CourseEnroll> getCourseEnrollListByUserId(Long userid) {
		// TODO Auto-generated method stub
		String jpql = "from CourseEnroll where userId = ?1";
		Map<String, Object> params = new HashMap<>();
		params.put("1", userid);
		return cedao.find(jpql, params);
	}

}
